package org.example.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcTest {
    public static void main(String[] args) {
        try {
            // 1
            Class.forName("com.mysql.cj.jdbc.Driver");
            // 2
            Connection connection = DriverManager.getConnection(
                    "jdbc:mysql://61.164.246.68:3306/sq_subsoil20",
                    "sq_subsoil20",
                    "@jGFja4696");
            // 3
            Statement statement = connection.createStatement();
            // 4
            ResultSet resultSet = statement.executeQuery("select * from exam_user");
            // 5
            while ( resultSet.next() ){
                System.out.println("id: " + resultSet.getInt("id"));
                System.out.println("userCode: " + resultSet.getString("userCode"));
                System.out.println("userName: " + resultSet.getString("userName"));
                System.out.println("javaScore: " + resultSet.getInt("javaScore"));
            }
            // 6
            resultSet.close();
            statement.close();
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
